package com.tencent.hummingbird.portal.mapper;

import com.tencent.hummingbird.portal.pojo.Permission;
import com.tencent.hummingbird.portal.pojo.Role;
import com.tencent.hummingbird.portal.pojo.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tencent.hummingbird.portal.vo.UserInfoVO;
import com.tencent.hummingbird.portal.vo.UserVO;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* <p>
    *  Mapper 接口
    * </p>
*
* @author yxb
* @since 2024-01-10
*/
@Repository

public interface UserMapper extends BaseMapper<User> {
    @Select("select * from user where username = #{username}")
    User findUserByUsername(String username);

    @Select("select\n" +
            "u.username , p.name\n" +
            "from user u\n" +
            "left join user_role ur on u.id=ur.user_id\n" +
            "left join role r on r.id=ur.role_id\n" +
            "left join role_permission rp on r.id=rp.role_id\n" +
            "left join permission p on p.id=rp.permission_id\n" +
            "where u.id=#{id}")
    List<Permission> findUserPermissionsById(Integer id);
    @Select("select * from user where type=1")
    List<User> selectTeachers();
    @Select("select id,username,nickname from user where username = #{username}")
    UserVO findUserVOByUserName(String username);

    @Select("select r.id,r.name" +
            " from user u" +
            " left join user_role ur on u.id=ur.user_id" +
            " left join role r on r.id=ur.role_id" +
            " where u.id=#{userId}")
    List<Role> findUserRolesById(Integer userId);

    @Select("SELECT COUNT(*)\n" +
            "FROM user_question uq\n" +
            "LEFT JOIN question q\n" +
            "ON uq.question_id = q.id\n" +
            "WHERE uq.user_id = #{userId} AND q.status != 2")
    Integer countTasks(Integer userId);

    @Update("UPDATE USER SET PASSWORD=#{password} WHERE username=#{userName} ")
    Integer resetPassword(String password,String userName);

    @Select("select nickname,sex,birthday,self_introduction  from user where username = #{username}")
    UserInfoVO selectUserInfoVOByUserName(String username);

    @Select("select * from user where nickname = #{nickName}")
    User findUserByUserNickName(String nickName);




}
